#include<iostream>
#include"share.h"
#include <sys/shm.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/ipc.h>

using namespace std;

int main()
{
    cout<<"------------------------------------------"<<endl;
    int shmid=shmget(shm_key,ShmSize,IPC_CREAT);//创建并获取共享内存
    if(shmid==-1)
    {
        cout<<"获取共享内存失败"<<endl;
        return 2;
    }
    int* shmaddr=(int*)shmat(shmid,nullptr,0);//挂载共享内存


    //进程间通信
    while(true)
    {
        int r_msg;
        r_msg=*shmaddr;
       
        cout<<r_msg<<endl;
        sleep(2);
    }

    shmdt(shmaddr);//去除共享内存
    return 0;
}